URLs

URLs are one of the most important features of HTML, because they allow HTML documents to function as hypertext documents. A URL is the address of a file (and possibly a specific location in that file), written in a format that a Web server understands, and which a browser can use to access the file over the Web. An example of a URL is:

http://www.sq.com/doc/tutorial.html

Most of HoTMetaL's commands for working with URLs are in the Links menu.

Where URLs appear

URLs are contained in certain designated `link' elements. They are attributes of the element, which means that they are values that are associated with the element, but which are not part of the content of the element (that is, text or sub-elements). Each attribute has a name and a value. (These are actually stored inside the start-tag of an element in an HTML file-you can see this if you use a text editor to open the file).

The elements that contain URLs are:

If the mouse pointer is over one of these elements, its URL is displayed in the message area in the lower left corner of the HoTMetaL window.

If the mouse pointer is over one of these elements, its URL is displayed in the message area in the lower left corner of the HoTMetaL window.

Two kinds of URLs

URLs can be divided into two groups: complete URLs and relative URLs. A complete URL contains the following parts:

Consider the example at the beginning of this section:

http://www.sq.com/doc/tutorial.html

Here the scheme is `http', the server address is `www.sq.com', and the path part of the URL is `doc/tutorial.html'.

Note: The path/filename is often omitted in the URL of a site's home page. The server will return the file `index.html' by default. For example, `http://www.sq.com/' is the URL for SoftQuad's home page.

A relative URL will be missing some of this information, and a browser will have to obtain the missing information from the URL of the document that contains the relative URL.

Creating URLs with HoTMetaL

HoTMetaL makes it easy to create and edit URLs, by way of the Edit URL... command in the Links menu.

To use this command you should:

If the current element is A, clicking on the ANCHICON toolbar button is equivalent to choosing the Edit URL... command; similarly, clicking on the IMGICON toolbar button when the current element is IMG invokes this command.

Edit URL... is disabled if the current element is not one of the ones that can contain a URL. The Edit URL dialog box comes up by default when you insert an A element (except when you insert it with the Name Target... command.

URLs for images

Choosing Edit URL... when the current element is IMG results in slightly different behavior than with other link elements. The first dialog box you see lets you enter information used only for images. If you click on the [Edit...] button in this dialog box, you will get a dialog that is identical to the Edit URL dialog, with one exception, noted below. See the chapter Working with images for more information.

The `Edit URL' dialog box


URL
The Edit URL dialog box contains the following controls for creating a URL:

Note: The dialog box used to edit the URL of of an image (IMG) element does not have the `Name/Query' control group.

How HoTMetaL constructs the URL

HoTMetaL creates a URL with the correct syntax from the information you've entered. Suppose you have entered the following:

From this information, HoTMetaL constructs this URL:

http://www.sq.com/orwell/homage.html#catalunya

Notice that HoTMetaL inserts the `/' between the host and the path. Since this scheme specifies that the path starts with a slash, you don't have to type it yourself. In fact, in this case, if you do start the name with a slash, HoTMetaL will ignore it. HoTMetaL also inserted the `#' before `catalunya'.

Note: Certain characters will be converted into an `escape sequence' if they are entered into the Edit URL dialog box. In particular, a tilde (~) will be changed to `%7E', a number sign (#) to `%23', and a space to `%20'. These forms are equivalent to the characters they replace and are interpreted correctly by all browsers.

Using the URL hotlist

HoTMetaL lets you maintain a hotlist of frequently used URLs. When you need to insert one of these URLs, you can just pick it from the list instead of having to enter the information over again.

To add the URL you're currently editing to the hotlist:

You'll then see a dialog box that displays the URL and lets you enter a description. This description is how the URL will be displayed in the hotlist dialog box.

To pick a URL from the hotlist:

A dialog box will appear, displaying the description of each URL in the hotlist.

To delete a URL from the hotlist:

To append a Mosaic hotlist or Netscape bookmarks file to the HoTMetaL hotlist:

Pointing to a specific location

Creating a URL that points to a specific location in a document is very easy. Here is an example:

http://www.sq.com/authors/orwell/homage.html#madrid

The characters `#madrid' at the end of this URL point to a specific location in the document that the URL refers to. For this link to work:

Creating `source' and `target' links in HoTMetaL

The quickest way to create the links is to use the Name Target... and Connect Link commands in the Links menu (or the equivalent toolbar buttons).

HoTMetaL gives you a dialog box in which to enter a name for the target link (`madrid' in the example above). If there is a selection when you click on the toolbar button, the first word in the selection will appear in the dialog box by default, but you can enter something else if you want. Link names typically consist of one word, but you can enter more.

HoTMetaL inserts an A element, surrounding the selection if there is one. (This element's NAME attribute will be set to the value you entered.)

HoTMetaL inserts an A element, surrounding the selection if there is one. This element's URL will point to the target link. Since the `path' part of this URL will refer to the local directory containing the document with the target link, you'll have to modify the URL before putting the document on the Web. See the section Moving your files to the web for more information.

You can perform other actions in between creating the two links, but HoTMetaL will remember only the most recent target link that you created with Name Target... (or the equivalent toolbar button).

If it's not convenient to use Connect Link (perhaps you want to enter all the target or source links first) you can use Insert Anchor... or the equivalent toolbar button to create the source links. In this way you can create the links in any order. To create a source link:

HoTMetaL inserts an A element and brings up the Edit URL dialog box.

Use Name Target... in the usual way to create the target links.

Syntax of URLs

The information in URLs has to be arranged in a way that the browsers and servers can understand it-in other words, it has to conform to the correct URL syntax.

Since the Edit URL... command helps you create URLs, you don't usually have to remember the details of the syntax: we've included this information here anyway because we believe that it will help you create URLs if you know what's really going on when you make a URL.

There are actually several URL formats, but fortunately most of the ones you'll have to use fall into two groups.

Files on a Web server

When you create a link to another HTML document or to an image, you'll usually be specifying a file on a Web server. In this case, the parts must be arranged in the following order:

  1. The scheme, which will be http.
  2. The characters `://'.
  3. The server address, e.g., www.sq.com.
  4. The `/' character.
  5. The path/filename.

The URL syntax requires that directory names in the path part of the URL be separated by slashes.

If you're creating this kind of URL with the Edit URL... command, choose the `http' scheme. Then you just need to enter the server address and path/filename: HoTMetaL will construct the URL for you.

Files on your system

If a URL specifies a file on your local system, rather than a file on a Web server, you would write the URL a little differently. You can refer to a file on your local disk only while you're developing and testing your document. When the document is published on the Web, it should refer only to other files available over the Web. See the section Moving your files to the Web for information on how to convert `local' URLs to URLs for the Web.

If you're creating this kind of URL with the Edit URL... command, choose the `file' scheme. Then you just need to enter the path/filename. Notice that you don't need a server address, since your local disk is assumed to be the `server'.

Relative URLs

Relative URLs (also called partial URLs) do not contain the complete information required for a browser to locate the file they refer to. For example, the scheme or network address could be missing.

Reasons to use a relative URL

Some of the advantages of using relative URLs over complete URLs are:

Base URLs

The browser has to figure out the missing information, based on the URL of the document that contains the relative URL (this is called the `base URL'). The browser has to construct a complete URL by combining the the relative URL with the relevant information from the base URL.

The base URL can come from one of two sources.

  1. If the current document contains a BASE element, then the URL specified in this element is used as the base URL for all relative URLs in the document. You should put a BASE element in your document if it contains relative URLs and you expect users to download the document to their local systems and browse it later.
  2. If there is no BASE element, the URL that the browser used to retrieve the current document will be the base URL.

Interpreting relative URLs

The following guidelines are slightly simplified and don't represent everything that can be said about interpreting relative URLs, but they cover the most frequently encountered cases. Remember that the process being described here is being done `internally' by the browser when it's interpreting the relative URL: the browser doesn't actually modify the URLs in your document.

  1. Relative URLs can start with one of the following:
  2. If the relative URL starts with `//', then the only thing missing is the scheme (http, etc.). In this case the scheme is inherited from the base URL to make a complete URL.
  3. If the relative URL starts with a single slash, then the scheme and the server address are missing. Both of these will be inherited from the base URL to make a complete URL. For example:
    /orwell/face.gif
    A file with this URL will be retrieved with the same scheme and from the same server as the document that contains the URL.
  4. If the relative URL starts with a directory or filename, then the procedure that a browser will use to make a complete URL is to remove the filename from the base URL and then append the relative URL to it. For example, suppose the relative URL is:
    orwell/homage.htm
    and the base URL is:
    http://www.sq.com/authors/contents.htm
    The browser removes the filename from the base URL to get:
    http://www.sq.com/authors/
    Now the browser appends the relative URL to this to get the complete URL:
    http://www.sq.com/authors/orwell/homage.htm
  5. A couple of special characters can occur in relative URLs: If the complete URL that you get by combining the base and relative URL contains the characters `/../', e.g.,
    http://www.sq.com/authors/../orwell/homage.htm
    then the browser interprets this by removing the directory that precedes those characters from the URL. The resulting URL from the last example would be:
    http://www.sq.com/orwell/homage.htm
    The directory `authors' has been removed.

    If the URL contains the characters `/./' then the browser will simply remove `./' from the resulting URL.

    These characters aren't interpreted as special characters unless they occur as the only thing between two slashes (`/../' or `/./'). For example, the sequence `/tom../' just refers to a directory called `tom..'.

Creating relative URLs with HoTMetaL

If you're creating a relative URL with HoTMetaL's Edit URL... command, leave the Scheme text entry box blank, and enter the required information in the Path text entry box.

The `mailto' scheme

The mailto scheme is used:

Inside an A or FORM element, as appropriate:

The resulting URL contains the `mailto' scheme, followed a mail address, such as `charles@windsor.org'.

In a form, there is one more thing you have to do in order to use mailto:

Some browsers do not support mailto. Also, in order for this feature to work if your system is behind a firewall, you may need to configure your browser to use the correct proxy server.

Displaying URLs

By default, HoTMetaL displays the URLs associated with relevant elements in the prefix of the element's start-tag. If you want to hide the URLs, choose Hide URLs from the View menu: the URLs will disappear from the display, and the menu item will toggle to Show URLs. Clicking on Show URLs will cause the URLs to be displayed again.

When the mouse cursor is over an element containing a URL, the URL is displayed in the message area in the lower left corner of the HoTMetaL window.

Moving your files to the Web

Before a completed HTML document is moved to a WWW server, all URLs should refer to documents that are available on some WWW server. (While the document is being created, they may refer to documents on your local system.)

For example, when you are creating a document the URLs may consist of local filenames such as:

file:////home/squabble/rodney/orwell/catalonia.html

When the document is placed on your server, you must substitute URLs that refer to documents that are available on your server or some other server. For example:

http://www.sq.com/orwell/catalonia.html

The Publish... command gives you the opportunity to edit all the URLs, modifying them if necessary. This command is a form of `find and replace' for URLs.

When you choose Publish... you will get a dialog box containing two text entry boxes.
PUBLISH

The first box (labeled Change URLs From) contains a part of the URL that you want to change; the second box (labeled To) contains the text that you want to change it to. You can enter text in these boxes to replace the default text.

If there were a large number of URLs for which you needed to change a local directory such as file:////home/squabble/rodney to a server address, such as http://www.sq.com, you could enter:

file:////home/squabble/rodney

in the Change URLs From text entry box, and:


http://www.sq.com

in the To text entry box

Finding and replacing URLs

When you click on the [Find Next] button, HoTMetaL finds the next element that has a URL matching the Change URLs From text. The insertion point is placed inside that element, and the document scrolls to its location. The search starts at the insertion point or selection.

Clicking on the [Replace] button will change the text you're searching for to the text in the To box.

Clicking on the [Replace All] button will make this change for all URLs in the document that contain the Change URLs From text. This also causes the dialog box to be dismissed.

This form of `find and replace' matches only starting at the first character of the URL.